using Spine;
using Spine.Unity;
using System;
using System.Collections;
using UnityEngine;

public class EquipmentController : MonoBehaviour
{
	[Serializable]
	public class SlotRegionPair
	{
		[SpineSlot("", "", false, true)]
		public string slot1;

		[SpineAtlasRegion("")]
		public string[] region;
	}

	public int typeOfWeapon;

	[SerializeField]
	protected bool inheritProperties = true;

	public AtlasAsset atlasAsset;

	public SlotRegionPair[] attachments;

	private int id;

	private Atlas atlas;

	private void Update()
	{
		changeWeapon();
	}

	public void changeWeapon()
	{
		atlas = atlasAsset.GetAtlas();
		AtlasAttachmentLoader atlasAttachmentLoader = new AtlasAttachmentLoader(atlas);
		SkeletonAnimation component = GetComponent<SkeletonAnimation>();
		float scale = component.skeletonDataAsset.scale;
		if (GameManager.levelUpgrade[typeOfWeapon] >= 0)
		{
			id = GameManager.levelUpgrade[typeOfWeapon];
		}
		else
		{
			id = 0;
		}
		IEnumerator enumerator = attachments.GetEnumerator();
		while (enumerator.MoveNext())
		{
			SlotRegionPair slotRegionPair = (SlotRegionPair)enumerator.Current;
			RegionAttachment regionAttachment = atlasAttachmentLoader.NewRegionAttachment(null, slotRegionPair.region[id], slotRegionPair.region[id]);
			regionAttachment.Width = regionAttachment.RegionOriginalWidth * scale;
			regionAttachment.Height = regionAttachment.RegionOriginalHeight * scale;
			regionAttachment.UpdateOffset();
			Slot slot = component.skeleton.FindSlot(slotRegionPair.slot1);
			slot.Attachment = regionAttachment;
		}
	}
}
